package com.hooda.controller;

import cn.com.duiba.credits.sdk.CreditTool;
import com.alibaba.druid.support.json.JSONUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author zhangzp
 * @version 1.0, 2021/10/14
 */
@RestController
@RequestMapping("/duiba")
public class DuibaController {

    @Autowired
    private CreditTool creditTool;

    @RequestMapping("/creditConsume")
    public String creditConsume(@RequestParam Map<String, String> parameters) {
        System.out.println("duiba credit consume :" + JSONUtils.toJSONString(parameters));
        return "{\n" +
                "    \"status\":\"ok\"，\n" +
                "    \"errorMessage\":\" \"，\n" +
                "    \"bizId\":\"20140730192133033\",\n" +
                "    \"credits\":\"100\"\n" +
                "}\n";
    }

    @RequestMapping("/creditNotify")
    public String creditNotify(@RequestParam Map<String, String> parameters) {
        System.out.println("duiba credit notify :" + JSONUtils.toJSONString(parameters));
        return "ok";
    }

    @RequestMapping("/virtualConsume")
    public String virtualConsume(@RequestParam Map<String, String> parameters) {
        System.out.println("duiba virtual consume :" + JSONUtils.toJSONString(parameters));
        return "{\"status\":\"success\",\"credits\":\"10\", \"supplierBizId\":\"no123456\"}";
    }

    @RequestMapping("/buildUrl")
    public String buildUrl(String url, @RequestParam("parameters") Map<String, String> parameters) {
        return creditTool.buildUrlWithSign(url, parameters);
    }

}
